﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace CrossLine
{
    class WebUtil
    {
        public static string GetWebContent(string Url)
        {
            string strResult = "";
            HttpWebRequest request = null;
            HttpWebResponse response = null;
            Stream streamReceive = null;
            StreamReader streamReader = null;
            try
            {
                request = (HttpWebRequest)WebRequest.Create(Url);
                //声明一个HttpWebRequest请求 
                request.Timeout = 1000;
                //设置连接超时时间 
                request.Headers.Set("Pragma", "no-cache");
                response = (HttpWebResponse)request.GetResponse();
                streamReceive = response.GetResponseStream();
                Encoding encoding = Encoding.GetEncoding("GB2312");
                streamReader = new StreamReader(streamReceive, encoding);
                strResult = streamReader.ReadToEnd();

            }
            catch
            {

            }
            finally
            {
                response.Close();
                streamReceive.Close();
                streamReader.Close();
            }
            return strResult;
        }

        //http://vip.stock.finance.sina.com.cn/quotes_service/view/CN_TransListV2.php?num=105&symbol=sz000600
        //http://market.finance.sina.com.cn/transHis.php?symbol=sh600292&date=2016-07-27
        public static string transHis(string stock_no)
        {
            StringBuilder url = new StringBuilder("http://vip.stock.finance.sina.com.cn/quotes_service/view/CN_TransListV2.php?num=105&symbol=");
            url.Append(stock_no );
            //得到指定Url的源码 
            return GetWebContent(url.ToString());
        }

        public static string curDate(string stock_no)
        {
            StringBuilder url = new StringBuilder("http://hq.sinajs.cn/list=");
            url.Append(stock_no);
            //得到指定Url的源码 
            return GetWebContent(url.ToString());
        }
    }
}
